#----------------------------
# Name: Charlie Bossi
# Project: Madlibs.py
# Period: 2
# Start Date: 9/17/2013
# Last Revision Date: 9/17/2013
# Version: 1.0.1
#----------------------------

swearFilter = ["dumb",
               "stupid",
               "retard",
               "anal",
                "arse",
                "ass",
                "ballsack",
                "balls",
                "bastard",
                "bitch",
                "biatch",
                "bloody",
                "blowjob",
                "blow job",
                "bollock",
                "bollok",
                "boner",
                "boob",
                "bugger",
                "bum",
                "butt",
                "buttplug",
                "clitoris",
                "cock",
                "coon",
                "crap",
                "cunt",
                "damn",
                "dick",
                "dildo",
                "dyke",
                "fag",
                "feck",
                "fellate",
                "fellatio",
                "felching",
                "fuck",
                "f u c k",
                "fudgepacker",
                "fudge packer",
                "flange",
                "Goddamn",
                "God damn",
                "hell",
                "homo",
                "jerk",
                "jizz",
                "knobend",
                "knob end",
                "labia",
                "lmao",
                "lmfao",
                "muff",
                "nigger",
                "nigga",
                "omg",
                "penis",
                "piss",
                "poop",
                "prick",
                "pube",
                "pussy",
                "queer",
                "scrotum",
                "sex",
                "shit",
                "s hit",
                "sh1t",
                "slut",
                "smegma",
                "spunk",
                "tit",
                "tosser",
                "turd",
                "twat",
                "vagina",
                "wank",
                "whore",
                "wtf",
                "yolo",
                "YOLO",
                "5weg",
                "5wag"]
def displayStartScreen():
    print "Madlibs"
    raw_input("Press Enter to Continue")
    
def displayEndScreen():
    print "Goodbye"
    raw_input("Press Enter to Exit")

def getMenuOption(maxOption):
    option = ""
    goodOption = False
    while not goodOption:
        option = raw_input("Enter Number or Q> ")
        option = option.upper()
        for num in range(1, maxOption+1):
            if option == str(num):
                goodOption = True
        if option == 'Q':
            goodOption = True
        if not goodOption:
            print "Please pick a valid option!"
    return option
    
def wordtest (string, word):
    found = False
    testChar = 0
    for char in string:
        #print char, word[testChar]
        if char == word[testChar]:
            if testChar < len(word):
                testChar += 1
            else:
                found = True
    if testChar == len(word):
        found = True
    return found

        
def menu(options):
    print "------Please Select a Story------"
    print " [1] The End of the Day"
    print " [2] My New Pet"
    print " [3] Plane Crash"
    print " [Q] Quit"
    print "----------------------------------"
    option = getMenuOption(options)
    return option
    
def getWord(prompt):
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input(prompt)
        if word.lower() not in swearFilter:
            if not wordtest(word, "swag"):
                if not wordtest(word, "sweg"):
                    goodWord = True
            
        else:
            print "Naughty player...please be polite."
        if not goodWord:
            print "Try again"
    return word
    
def getNumber(prompt, max = "", min = ""):
    num = ""
    goodNum = False
    while not goodNum:
        isNum = True
        num = raw_input(prompt)
        for character in num:
            if character not in "0123456789":
                isNum = False
        if min != "":
            if isNum:
                if float(num) < min:
                    isNum = False
        if max != "":
            if isNum:
                if float(num) > max:
                    isNum = False
        if isNum:
            goodNum = True
        else:
            print "Not a valid number, try again."
    return num
        
def story1():
    place1 = getWord("Enter a Place: ")
    name = getWord("Enter a Name: ")
    noun = getWord("Enter a Noun: ")
    adj = getWord("Enter a Adjective: ")
    car = getWord("Enter a Vehicle: ")
    story = "It was near the end of the day at"
    story += " " + place1 + ". " 
    story += name + " was leaving work when "
    story += "a giant " + adj + " " + noun + " flew out of the sky and attacked him. "
    story += name + " swerved franticaly to not be attacked by the " + noun + ". "
    story += name + " quicky ran into a tunell but the " + noun + "followed. "
    story += "Luckily a " + car + " was going through the tunnel and squashed the " + noun + "."
    print story 
    
def story2():
    name = getWord("Enter a name: ")
    age = getNumber("Enter a number: ")
    noun = getWord("Enter a Noun: ")
    adj = getWord("Enter a Adjective: ")
    verb = getWord("Enter a verb:")
    story = "I got a new pet and I named it"
    story += " " + name + ". "
    story += "I think " + name + " is"
    story += " " + age + " years old. "
    story += "I think its time to take " + name + " for a walk. "
    story += " " + name + " fell in love with a " + noun + " during our walk."
    story += " " + name + " couldent move the " + noun + " because it was so " + adj + "."
    story += " " + name + " decided to " + verb + " all over it instead."
    print story

def story3():
    name = getWord("Enter a name: ")
    noun = getWord("Enter a Noun: ")
    time = getWord("Enter a increment of time: ")
    story = "Plane Crash"
    story += "My name is " + name + "."
    story += "I was flying over the atlantic when my plane crashed"
    story += "I survived the crash..."
    story += "When I swam from the plane and saw a " + noun + "."
    story += "I quickly swam over to the " +noun+ "."
    story += "Several " + time + " later I was able to signal a ship"
    story += "I survived."
    print story
def run():
    displayStartScreen()
    choice = ""
    while choice != 'Q':
        choice = menu(3)
        if choice == '1':
            story1()
        elif choice == '2':
            story2()
        elif choice == '3':
            story3()
        elif choice == 'Q':
            displayEndScreen()
        else:
            print "Something Awful Ocurred..."
    exit()
run()